#pragma once

#include <linux/types.h>
#include <linux/gfp_types.h>
#include <linux/stddef.h>

void *kmalloc(unsigned long size, gfp_t flags);
void kfree(const void *object);

/**
 * kzalloc - allocate memory. The memory is set to zero.
 * @size: how many bytes of memory are required.
 * @flags: the type of memory to allocate (see kmalloc).
 */
static inline void *kzalloc(unsigned long size, gfp_t flags)
{
    return kmalloc(size, flags | __GFP_ZERO);
}

static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
{
    size_t bytes;

    bytes = n * size;
    if (size && (bytes / size) != n)
        return NULL;

    return kmalloc(bytes, flags);
}

/**
 * kcalloc - allocate memory for an array. The memory is set to zero.
 * @n: number of elements.
 * @size: element size.
 * @flags: the type of memory to allocate (see kmalloc).
 */
#define kcalloc(n, size, flags) kmalloc_array(n, size, (flags) | __GFP_ZERO)
